package pseuodrandom;
//Experiment implementing pseudo random numbers: too fiddly

import java.util.*;

public class pseudorandom {
	BitSet b = new BitSet(8);
	
	public static void main(String args[]){
		pseudorandom b = new pseudorandom();
		for(int i=0;i<100;i++){
			System.out.println(toBitString(b.next()));
		}
		
	}
	
	public pseudorandom(){
		b.set(7,true);
		b.set(4,true);
	}
	
	public static String toBitString(BitSet b){
		String s = "";
		for(int i=0;i<8;i++){
			if(b.get(i)){
				s = s+"1";
			}
			else{ s = s+"0";}
		}
		return s;
	}
	
	public BitSet next(){
		BitSet old = (BitSet)b.clone();
		int x = 7;
		updateBits(x);
		return old;
	}
	
	public void updateBits(int n){
		if(n==0){
			b.set(n, tap());
		}
		else{
			b.set(n,b.get(n-1));
			updateBits(n-1);
		}
	}
	
	public boolean tap(){
		int[] tap = {6,5,4};
		boolean out=b.get(7);
		for(int i=0;i<tap.length;i++){
			out = out^b.get(tap[i]);
		}
		return out;
	}
	
	
	
	
	
	
}
